package com.fhj.bookshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fhj.bookshop.entity.Product;
import com.fhj.bookshop.mapper.ProductMapper;
import com.fhj.bookshop.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fu
 * @since 2023-12-12
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Autowired
    ProductMapper productMapper;
    @Override
    public Page<Product> productPageService(Integer pageCode, Integer pageSize,String proType){
        Page<Product> page =new Page<Product>(pageCode,pageSize);
        LambdaQueryWrapper<Product> wrapper=new LambdaQueryWrapper<>();
        if(!"".equals(proType)){
            wrapper.like(Product::getProType,proType);
        }
        productMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public Product findProductById(Integer proId) {
        LambdaQueryWrapper<Product> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Product::getProId,proId);
        return productMapper.selectOne(wrapper);
    }

    @Override
    public Page<Product> AdminProduct(Integer pageCode, Integer pageSize){
        Page<Product> page =new Page<Product>(pageCode,pageSize);
        LambdaQueryWrapper<Product> wrapper=new LambdaQueryWrapper<>();
        productMapper.selectPage(page,wrapper);
        return page;
    }


}
